var sdApp = angular.module('sdApp', ['ui.router', 'angularCharts', 'ui', 'ui.bootstrap', 'textAngular', 'angular-progress-arc', 'ngDialog']);
//var services = angular.module('myApp.services', []);

// this is run after angular is instantiated and bootstrapped
sdApp.run(function ($rootScope, $location, $http, $timeout, RESTService) {
    $rootScope.restService = RESTService;
    //$rootScope.urlPrefix = 'http://www.simplydecide.com/dev-red/api';
    //$rootScope.urlPrefix = 'http://localhost/SimplyDecide/trunk/api';
    $rootScope.urlPrefix = 'http://localhost/sd-red/api';
    //$rootScope.urlPrefix = 'http://localhost/SimplyDecide/trunk/api';
   // $rootScope.urlPrefix = 'http://localhost:8080/sd-red/api';
    
    $rootScope.stateCard = {
        userId: -1,
        firstName: '',
        lastName: '',
        email: ''
    }

    // async load constants
    $rootScope.constants = [];
    $rootScope.restService.get($rootScope.urlPrefix + '/menu', function (data) {
        var menuList = data.records;
        menuList = menuList.sort(function (a, b) {
            if (parseInt(a.results.count) > parseInt(b.results.count)) {
                return -1;
            } else if (parseInt(a.results.count) < parseInt(b.results.count)) {
                return 1;
            }
            return 0;
        })
        $rootScope.menuList = menuList;
    });

    $rootScope.restService.get($rootScope.urlPrefix + '/authenticate/user', function (data) {
        $rootScope.stateCard.userId = parseInt(data.userid);
        $rootScope.stateCard.email = data.email;
        $rootScope.stateCard.firstName = data.firstName;
        $rootScope.stateCard.lastName = data.lastName;
    });
});

sdApp.directive('mypopover', function ($compile,$templateCache) {

var getTemplate = function (contentType) {
    var template = '';
    switch (contentType) {
        case 'user':
            template = $templateCache.get("notification-template.html");
            break;
    }
    return template;
}
return {
    restrict: "A",
    link: function (scope, element, attrs) {
        var popOverContent;
      
        popOverContent = getTemplate("user");                  
        scope.dataObj = 'hello';
        var options = {
            content: $compile(popOverContent)(scope),
            placement: "bottom",
            html: true,
            date: scope.date
        };
        $(element).popover(options);
    }
};
});

